package com.ctshk.rpc.goods.mapper;

import com.ctshk.rpc.goods.base.CustomBaseMapper;
import com.ctshk.rpc.goods.entity.CommoditySpecificationsAttribute;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 商品规格属性表 Mapper 接口
 * </p>
 *
 * @author 姜斌文
 * @since 2021-04-12
 */
public interface CommoditySpecificationsAttributeMapper extends CustomBaseMapper<CommoditySpecificationsAttribute> {
	@Delete("DELETE FROM t_commodity_specifications_attribute t "
			+ "WHERE t.specifications_name_id = #{specificationsNameId} AND t.specifications_id = #{specificationsId}")
	void deleteByNameIdAndAttrId(@Param("specificationsNameId") Long specificationsNameId, @Param("specificationsId") Long specificationsId);

	@Select("select t.id, t.attribute_name from t_commodity_specifications_attribute t where t.specifications_name_id = #{specificationsNameId} and t.specifications_id = #{specificationsId}")
	List<CommoditySpecificationsAttribute> findCommoditySpecificationsAttributeListByNameIdAndSId(@Param("specificationsNameId") Long specificationsNameId, @Param("specificationsId") Long specificationsId);

	@Select("select t.id, t.attribute_name from t_commodity_specifications_attribute t where t.specifications_id = #{specificationsId} and t.is_deleted = 0")
	List<CommoditySpecificationsAttribute> findCommoditySpecificationsAttributeListBySpefificationsId(@Param("specificationsId") Long specificationsId);

	@Select("SELECT " +
			"	t.id, t.attribute_name " +
			"FROM t_commodity_specifications_attribute t " +
			"where " +
			"	t.specifications_id = #{specificationsId} " +
			"	AND t.specifications_name_id = #{specificationsNameId} " +
			"	AND t.attribute_name = #{attributeName} " +
			"	AND t.is_deleted = 0")
	List<CommoditySpecificationsAttribute> findCommoditySpecificationsAttributeByNameAndSIdAndName(@Param("specificationsNameId") Long specificationsNameId, @Param("specificationsId") Long specificationsId, @Param("attributeName") String attributeName);

}
